#encoding:utf-8
from __future__ import unicode_literals

import os
basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
    SSL_DISABLE = False
    SQLALCHEMY_RECORD_QUERIES = True
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 是否开启rabbitmq
    RABBIT_MQ = False
    # 开发环境以2个空格作为indent, 方便调试
    RESTFUL_JSON = {
        'indent': 2,
        'ensure_ascii': False,
        'sort_keys': True,
    }
    # 是否对用户进行鉴权
    VERIFY_PERMISSION = True
    # 标识是否开发环境
    IS_DEVELOPMENT = False

    # cache config
    CACHE_TYPE = 'redis'
    CACHE_KEY_PREFIX = 'iss'
    # token expire time
    TOKEN_EXPIRE = 60 * 60 * 24 * 14  # two weeks

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    IS_DEVELOPMENT = True
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
        'postgresql://postgres:123456@localhost/bell_iss'

    # 如果在开发环境需要使用redis, 则把下面的语句注释掉即可
    # CACHE_TYPE = 'null'



class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')
    WTF_CSRF_ENABLED = False
    VERIFY_PERMISSION = False
    CACHE_TYPE = 'null'
    CACHE_NO_NULL_WARNING = True


class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data.sqlite')
    RESTFUL_JSON = {
        'indent': None,
    }

    @classmethod
    def init_app(cls, app):
        Config.init_app(app)

class UnixConfig(ProductionConfig):
    @classmethod
    def init_app(cls, app):
        ProductionConfig.init_app(app)

        # log to syslog
        import logging
        from logging.handlers import SysLogHandler
        syslog_handler = SysLogHandler()
        syslog_handler.setLevel(logging.WARNING)
        app.logger.addHandler(syslog_handler)


config = {
    'default': DevelopmentConfig,

    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'unix': UnixConfig,
}